package net.xdclass.xdvideo.exception;

import net.xdclass.xdvideo.domain.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: xdvideo
 * @description: 异常处理控制器
 * @author: rZ
 * @create: 2019-11-06 10:25
 **/
@ControllerAdvice
public class XdExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonData handler(Exception e){

        if (e instanceof XdException){
           XdException xdException =  (XdException)e;
           return JsonData.buildError(xdException.getMsg(),xdException.getCode());
        }else {
            return JsonData.buildError("全局异常，未知错误");
        }
    }
}
